package cn.cpf.aop.annotation;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AopAspectDemo1 {

	private Logger logger = LoggerFactory.getLogger(AopAspectDemo1.class);


	//配置切入点,该方法无方法体,主要为方便同类中其他方法使用此处配置的切入点
	@Pointcut("execution(* cn.cpf.aop.annotation.AopObjectDemo.testAop())")
	public void aspect(){ }

//	@Before("aspect()")
//	public void beforeTest(JoinPoint joinPoint) {
//		logger.info(" before ");
//	}

	@Before("aspect()")
	public void beforeTest() {
		logger.info(" before no args");
	}

	@After("aspect()")
	public void after(JoinPoint joinPoint) {
		logger.info(" after ");
	}

	@AfterReturning(returning = "rst", value = "aspect()")
	public void afterReturn(JoinPoint joinPoint, Object rst) {
		logger.info(" afterReturn ");
	}

	@AfterThrowing(throwing = "e", value = "aspect()")
	public void afterThrow(JoinPoint joinPoint, Throwable e) {
		logger.info(" afterThrow ");
	}

	@Around("aspect()")
	public void around(ProceedingJoinPoint pjp) {
		logger.info(" around start ");
		try {
			pjp.proceed();
		} catch (Throwable throwable) {
			logger.info(" around throwable ");
			throwable.printStackTrace();
		}
		logger.info(" around end ");
	}


}
